/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-06
 * Time: 18:44
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

namespace patterns
{
	/// <summary>
	/// Base class for the Factory Method design pattern.
	/// 
	/// The derived class should state in its class definition what product is
	/// to be created. This is now a new factory, and by implementing the two
	/// Create-methods, it can produce new instances of this product
	/// </summary>
	public abstract class FactoryMethod<Product>
	{
		#region constructors
		
		/// <summary>
		/// Constructor, does nothing
		/// </summary>
		protected FactoryMethod()
		{
		}
		
		#endregion
		
		#region methods
		
		/// <summary>
		/// Gets an instance of this product based on the contents of the file at the specified location
		/// </summary>
		/// <param name="configFile">The location of the file holding information on the product</param>
		/// <returns>The new instance of the product</returns>
		public Product GetProduct(string configFile)
		{
			return CreateProduct(configFile);
		}
		
		/// <summary>
		/// Gets an instance of this product
		/// </summary>
		/// <returns>The new instance of the product</returns>
		public Product GetProduct()
		{
			return CreateProduct();
		}
		
		#endregion
		
		#region abstracts
		
		/// <summary>
		/// Creates the product to be returned. Does this based on the contents of the file at the specified location
		/// </summary>
		/// <param name="configFile">The location of the file holding information on the product</param>
		/// <returns>The new instance of the product</returns>
		protected abstract Product CreateProduct(string configFile);
		
		/// <summary>
		/// Creates the product to be returned
		/// </summary>
		/// <returns>The new instance of the product</returns>
		protected abstract Product CreateProduct();
		
		#endregion
	}
}
